import request from '@/config/axios'

export interface EvalWorkflowActionVO {
  targetStatus: number
  actionName: string
  actionType: string
}

export interface EvalWorkflowConditionCheckVO {
  canExecute: boolean
  errors: string[]
  warnings?: string[]
}

export interface EvalWorkflowTransitionReqVO {
  planId: number
  targetStatus: number
  comments?: string
}

export interface EvalWorkflowBatchProcessReqVO {
  planIds: number[]
  targetStatus: number
}

// 检查计划状态流转是否合法
export const isValidStatusTransition = (currentStatus: number, targetStatus: number) => {
  return request.get({ 
    url: `/eval/workflow/is-valid-transition?currentStatus=${currentStatus}&targetStatus=${targetStatus}` 
  })
}

// 执行计划状态流转
export const executeStatusTransition = (data: EvalWorkflowTransitionReqVO) => {
  return request.post({ url: '/eval/workflow/execute-transition', data })
}

// 获取计划可执行的下一步操作
export const getAvailableActions = (planId: number): Promise<EvalWorkflowActionVO[]> => {
  return request.get({ url: '/eval/workflow/available-actions?planId=' + planId })
}

// 检查计划是否满足发布条件
export const checkPublishConditions = (planId: number): Promise<EvalWorkflowConditionCheckVO> => {
  return request.get({ url: '/eval/workflow/check-publish-conditions?planId=' + planId })
}

// 检查计划是否满足开始评价条件
export const checkStartConditions = (planId: number): Promise<EvalWorkflowConditionCheckVO> => {
  return request.get({ url: '/eval/workflow/check-start-conditions?planId=' + planId })
}

// 检查计划是否满足完成条件
export const checkCompleteConditions = (planId: number): Promise<EvalWorkflowConditionCheckVO> => {
  return request.get({ url: '/eval/workflow/check-complete-conditions?planId=' + planId })
}

// 自动推进计划状态
export const autoAdvancePlanStatus = (planId: number) => {
  return request.post({ url: '/eval/workflow/auto-advance?planId=' + planId })
}

// 批量处理计划状态
export const batchProcessPlanStatus = (data: EvalWorkflowBatchProcessReqVO) => {
  return request.post({ url: '/eval/workflow/batch-process', data })
}

// 获取状态流转历史
export const getStatusTransitionHistory = (planId: number) => {
  return request.get({ url: '/eval/workflow/transition-history?planId=' + planId })
}

// 获取工作流统计信息
export const getWorkflowStatistics = () => {
  return request.get({ url: '/eval/workflow/statistics' })
}

// 获取工作流详情
export const getWorkflowDetail = (planId: number) => {
  return request.get({ url: '/eval/workflow/detail?planId=' + planId })
}

// 获取工作流步骤
export const getWorkflowSteps = (planId: number) => {
  return request.get({ url: '/eval/workflow/steps?planId=' + planId })
}

// 获取当前任务
export const getCurrentTasks = (planId: number) => {
  return request.get({ url: '/eval/workflow/current-tasks?planId=' + planId })
}

// 获取操作历史
export const getOperationHistory = (planId: number) => {
  return request.get({ url: '/eval/workflow/operation-history?planId=' + planId })
}
